<template>
	<view class="">
		<u-navbar title="分享" safeAreaInsetTop fixed placeholder>
			<view class="coreshop-navbar-left-slot" slot="left">
				<u-icon name="home" size="22" @click="goHome"></u-icon>
			</view>
		</u-navbar>
		<view class="center-box">
			<u-icon name="chat-fill" size="80" color="#2c2c2c"></u-icon>
			<view class="c-m-t-20 coreshop-percent-100">
				<u-button color="#5ab452" text="发送给好友" size="large" open-type="share"></u-button>
			</view>
			<view class="coreshop-flex coreshop-percent-100 c-m-t-30 coreshop-justify-between">
				<view class="coreshop-percent-48">
					<u-button text="前往商城" size="large" :plain="true" @click="goHome"></u-button>
				</view>
				<view class="coreshop-percent-48">
					<u-button text="回到管理端" size="large" :plain="true" @click="toMiniProgram"></u-button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return {
				shareCode: '',
				shareType: '',
				id: 0,
				shareData:{}
			}
		},
		onLoad(opt){
			console.log('接收数据', opt)
			this.shareType = opt.shareType
			this.id = opt.id
			this.shareCode = opt.shareCode
			this.getDetails()
		},
		methods: {
			getDetails(){
				const that = this
				const data = {
					id: parseInt(that.id)
				}
				if(that.shareType == that.$globalConstVars.shareType.goods){
					that.$u.api.goodsDetail(data).then(res=>{
						that.shareData = {
							title:res.data.name,
							path:`/pages/goods/goodDetails/goodDetails?id=${data.id}&shareCode=${that.shareCode}`,
							imageUrl:res.data.image || '/static/images/logo/logo.png'
						}
					})
				}else if(that.shareType == that.$globalConstVars.shareType.card){
					that.$u.api.CardItemDetial(data).then(res=>{
						that.shareData = {
							title:res.data.model.name,
							path:`/pages/cardbuy/cardbuyDetails/cardbuyDetails?id=${res.data.model.id}&shareCode=${that.shareCode}&type=1`,
							imageUrl:res.data.model.shareImageUrl || '/static/images/logo/logo.png'
						}
					})
				}else if(that.shareType == that.$globalConstVars.shareType.project){
					that.$u.api.ProjectGetDetial(data).then(res=>{
						that.shareData = {
							title:res.data.name,
							path:`/pages/reservation/seReservation?projectId=${res.data.id}&shareCode=${that.shareCode}&type=purchase`,
							imageUrl:res.data.image || '/static/images/logo/logo.png'
						}
					})
				}
			},
			onShareAppMessage(res){
				if (res.from === 'button') {
					return this.shareData
				}
			},
			toMiniProgram(){
				uni.navigateBackMiniProgram()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.center-box{
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -70%);
		width:670rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
</style>